#define _CRT_SECURE_NO_WARNINGS
//
// 
// 
/**
* Definition for singly - linked list.
* struct ListNode {
    *int val;
    *struct ListNode* next;
    *
};
*/


struct ListNode* removeElements(struct ListNode* head, int val)
{
    if (head == NULL)
    {
        return NULL;
    }
    struct ListNode* cur = head;
again:
    if (cur->val == val)
    {
        //cur = head;
        head = head->next;
        free(cur);
        cur = NULL;
        cur = head;
        if (cur != NULL)
        {
            goto again;
        }

    }
    while (cur != NULL)
    {
        if ((cur->next)->val == val)
        {
            struct ListNode* erase = cur->next;
            cur->next = (cur->next)->next;
            free(erase);
            erase = NULL;
        }

        if (cur->next != NULL)
        {
            cur = cur->next;
        }

    }
    return head;
}
//
